<!DOCTYPE HTML>
<html>
<head>
    <title>Todo</title>
    <link rel="stylesheet" href="/stylesheets/style.css">
    <script src="/scripts/jquery.min.js"></script>
    <link rel="stylesheet" href="/scripts/miniui/themes/default/miniui.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/icons.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/bootstrap/skin.css">
    <link rel="stylesheet" href="/editor/common.css">
    <script src="/scripts/miniui/miniui.js"></script>
</head>
<body  style="padding: 0;width: 100%;height: 100%;margin: 0">
<div class="mini-toolbar" style="text-align: center; line-height: 30px; border: 0px;" borderstyle="border:0;">
    <span>商品名称：</span><input  class="mini-textbox" type="text" id="title"/>

    <span>商品id：</span><input  class="mini-textbox" type="text" id="objectId"/>

    <input style="margin-right: 30px" type="button" value="查找" onclick="search()"/>
</div>
<div id="datagrid1" class="mini-datagrid" style="width:100%;height: 300px"
     url="/getdata/live/goods/list" idField="id" allowResize="true"
     sizeList="[10,30,50,100]" pageSize="10"
>
    <div property="columns">
        <div type="checkcolumn" width="20" ></div>
        <div field="goodsOId" width="80" align="center" headerAlign="center">商品ID</div>
        <div field="title" width="50" align="center" headerAlign="center">商品名称</div>
        <div field="picName"  width="30" renderer="onIconRenderer" align="center" headerAlign="center">商品图片</div>
        <div name="action" width="20" headerAlign="center" align="center" renderer="onActionRenderer" cellStyle="padding:0;">添加商品</div>
        <div field="createdAt" width="100"  align="center" headerAlign="center" allowSort="true">创建日期</div>
    </div>
</div>

<div class="mini-toolbar" style="text-align: center; line-height: 30px; border: 0px;" borderstyle="border:0;">
    直播绑定商品
</div>
<div id="datagrid2" class="mini-datagrid" style="width:100%;height: 300px"
     url="/getdata/live/bindGoods" idField="id" allowResize="true"
     sizeList="[10,30,50,100]" pageSize="10"
>
    <div property="columns">
        <div type="checkcolumn" width="20" ></div>
        <div field="goodsOId" width="80" align="center" headerAlign="center">商品ID</div>
        <div field="title" width="50" align="center" headerAlign="center">商品名称</div>
        <div field="picName"  width="30" renderer="onIconRenderer" align="center" headerAlign="center">商品图片</div>
        <div name="action" width="20" headerAlign="center" align="center" renderer="onActionRemoveRenderer" cellStyle="padding:0;">删除</div>
        <div field="createdAt" width="100"  align="center" headerAlign="center" >创建日期</div>
    </div>
</div>
<div class="mini-toolbar" style="text-align: center; padding-top: 8px; padding-bottom: 8px; border: 0px;" borderstyle="border:0;">
    <a class="mini-button" href="javascript:void(0)"  style="width: 60px;"><span class="mini-button-text " onclick="onOk()">确定</span></a>
    <span style="display:inline-block;width:25px;"></span>
    <a class="mini-button" href="javascript:void(0)"  style="width: 60px;"><span class="mini-button-text " onclick="onCancel()">取消</span></a>
</div>

</body>
<script type="text/javascript">
    //    var userStatus = [{ id: 1, text: '审核成功' }, { id: 0, text: '未审核'},{ id: 4, text: '审核失败'},{ id: 3, text: '审核中'}];
    var flag = 1;
    var tribeOId = '<%=tribeOId%>';
    var objectId = '<%=objectId%>';
    console.log(objectId)
    mini.parse();
    var grid = mini.get("datagrid1");
    var grid2 = mini.get("datagrid2");

    grid.load({tribeOId:tribeOId});
    grid2.load({objectId:objectId});
    grid.on("drawcell", function (e) {
        var  value = e.value;
        column = e.column;
        //将性别文本替换成图片
        if (column.field == "picName") {
            if(value) {
                e.cellHtml = '<img class="bigImg" onclick="bigImg()" src="http://tribemedia.aladada.com/' + value + '?imageMogr2/thumbnail/640x/format/jpg/interlace/1/auto-orient" width="30" height="30" alt="图片">';
            }else{
                e.cellHtml = '<img class="bigImg" onclick="bigImg()"  src="http://7xiuo5.com1.z0.glb.clouddn.com/fgImage.png?imageMogr2/auto-orient/thumbnail/!100x100r/gravity/Center/crop/100x100/quality/80/auto-orient" width="30" height="30" alt="图片">';
            }
        }
    });
    grid2.on("drawcell", function (e) {
        var  value = e.value;
        column = e.column;
        //将性别文本替换成图片
        if (column.field == "picName") {
            if(value) {
                e.cellHtml = '<img class="bigImg" onclick="bigImg()" src="http://tribemedia.aladada.com/' + value + '?imageMogr2/thumbnail/640x/format/jpg/interlace/1/auto-orient" width="30" height="30" alt="图片">';
            }else{
                e.cellHtml = '<img class="bigImg" onclick="bigImg()"  src="http://7xiuo5.com1.z0.glb.clouddn.com/fgImage.png?imageMogr2/auto-orient/thumbnail/!100x100r/gravity/Center/crop/100x100/quality/80/auto-orient" width="30" height="30" alt="图片">';
            }
        }
    });

    function search() {
        var title = mini.get("title").getValue();
        var goodsOId = mini.get("objectId").getValue();
        grid.load({
            title: title,
            goodsOId:goodsOId,
            tribeOId:tribeOId,
        });
    }
    $("#name,#objectId,#tel").bind("keydown", function (e) {
        if (e.keyCode == 13) {
            search();
        }
    });



    function onBirthdayRenderer(e) {
        var value = e.value;
        if (value) return mini.formatDate(value, 'yyyy-MM-dd hh:mm:ss');
        return "";
    }
    function statusRenderer(e) {
        var value = e.value;
        if (value==1) {
            return (value, '正常')
        }else if(value==0){
            return (value, '关闭')
        }
    };
    function GetSelecteds() {
        var rows = grid.getSelecteds();
        return rows;
    }
    function GetData() {
        var rows = grid.getSelecteds();
        var ids = [], texts = [];
        for (var i = 0, l = rows.length; i < l; i++) {
            var row = rows[i];
            ids.push(row.objectId);
            texts.push(row.name);
        }
        var data = {};
        data.id = ids.join(",");
        data.text = texts.join(",");
        return data;
    }

    //////////////////////////////////
    function CloseWindow(action) {
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else window.close();
    }

    function onOk() {
        CloseWindow("ok");
    }
    function onCancel() {
        CloseWindow("cancel");
    }

    function onActionRenderer(e) {

        var grid = e.sender;
        var record = e.record;
        var uid = record._uid;
        var goodsOId = record.goodsOId;
        var objectId = record.objectId;
        s = '<a class="Edit_Button" href="javascript:permit(\''+goodsOId+'\')">添加</a> '
        return s;
    };
    function permit(goodsOId) {
        console.log(goodsOId,objectId);
        $.ajax({
            url: "/getdata/live/goods/add",
            type: 'post',
            data: {
                goodsOId:goodsOId,
                objectId:objectId,
            },
            cache: false,
            success: function (res) {
                if (res == 1) {
                    grid2.reload();
                } else {
                    alert("出现错误");
                }

            },

            error: function (error) {
                console.log(error)
            }
        });
    }
    function onActionRemoveRenderer(e) {

        var grid = e.sender;
        var record = e.record;
        var uid = record._uid;
        var goodsOId = record.goodsOId;
        var objectId = record.objectId;
        s = '<a class="Edit_Button" href="javascript:rePermit(\''+goodsOId+'\')">删除</a> '
        return s;
    };

    function rePermit(goodsOId) {
        console.log(goodsOId,objectId);
        $.ajax({
            url: "/getdata/live/goods/remove",
            type: 'post',
            data: {
                goodsOId:goodsOId,
                objectId:objectId,
            },
            cache: false,
            success: function (res) {
                if (res == 1) {
                    grid2.reload();
                } else {
                    alert("出现错误");
                }

            },

            error: function (error) {
                console.log(error)
            }
        });
    }
</script>
</html>